<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//分类表
class Cate_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->content_category_table = 'content_category';
        $this->gift_category_table = 'gift_category';
    }
    
    function content_cate_get($where){
        return $this->db->select('*')->from($this->content_category_table)->where($where)->order_by('id desc')->get()->row_array();
    }
    
    function get_list($where){
        return $this->db->select('*')->from($this->table)->where($where)->order_by('create_time desc')->get()->result_array();
    }
    
    function gift_cate_list($where){
        return $this->db->select('*')->from($this->gift_category_table)->where($where)->order_by('sort,id desc')->get()->result_array();
    }
    
    function content_cate_list($where){
        return $this->db->select('*')->from($this->content_category_table)->where($where)->order_by('id asc')->get()->result_array();
    }
    
    //递归生成树形数组
    public function tree($table,$pid='0') {
        $tree = array();
        foreach($table as $row){
            if($row['pid']==$pid){
                $tmp = $this->tree($table,$row['id']);
                if($tmp){
                        $row['children']=$tmp;
                }else{
                        $row['leaf'] = true;
                }
                $tree[]=$row;     
            }
        }
        return $tree;        
    }
}
